package com.pengtu.gsj.controller.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.BaseController;
import com.pengtu.gsj.entity.app.Trajectory;
import com.pengtu.gsj.entity.app.Warning;
import com.pengtu.gsj.entity.check.CheckProject;
import com.pengtu.gsj.service.check.CheckModuleService;
import com.pengtu.gsj.service.check.CheckProjectService;
import com.pengtu.gsj.service.system.SysmenuManagerService;
import com.pengtu.gsj.service.system.TrajectoryService;
import com.pengtu.gsj.service.system.WarningService;

/**
 * 
 * 预警控制层
 * WarningController
 * 
 * 2017年9月2日 下午2:45:18
 * 
 * @version 1.0.0
 *
 */
@Controller
@RequestMapping("warn")
public class WarningController extends BaseController {
	
	@Autowired
	private WarningService warningService;
	@Autowired
	private CheckProjectService checkProjectService;
	@Autowired
	private SysmenuManagerService sysmenuManagerService;
	@Autowired
	private TrajectoryService trajectoryService;
	@Autowired
	private CheckModuleService checkModuleService;

	@RequestMapping("listInfo")
	@ResponseBody
	public Map<String, Object> getWarnings(){
		Map<String, Object> map = new HashMap<String, Object>();
		//1.获取预警消息
		List<Warning> list = warningService.getWarnings();
		
		//获取系统中唯一一个国检、省检项目
		//2.获取国检项目
		List<CheckProject> countryProjects = checkProjectService.getCheckProjectsByType("0");
		//获取省检项目
		List<CheckProject> provinceProjects = checkProjectService.getCheckProjectsByType("1");
		List<Map<String, Object>> countryList = new ArrayList<Map<String,Object>>();
		List<Map<String, Object>> provinceList = new ArrayList<Map<String,Object>>();
		
		if (countryProjects.size() > 0) {
		 countryList = checkModuleService.getCheckResultByProjectId(countryProjects.get(0).getId());
		}
		if (provinceProjects.size() > 0) {
			 provinceList = checkModuleService.getCheckResultByProjectId(provinceProjects.get(0).getId());
		}
		
		//3.获取前10条历史轨迹
		List<Trajectory> trajectories = new ArrayList<Trajectory>();
			trajectories = trajectoryService.getTrajectories();
		map.put("warn", list);
		map.put("countryList", countryList);
		map.put("provinceList", provinceList);
		map.put("trajectories", trajectories);
		return map;
	}
}
